package com.woniuxy.stage3demo.controller.chenyuxuanController;

import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.chenyuxuanBean.OptLogBean;
import com.woniuxy.stage3demo.bean.ResultMsg;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.pageHelper.TableResult;
import com.woniuxy.stage3demo.service.chenyxuanService.IOptService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 日志controller
 */
@RestController
@RequestMapping("optLog")
public class OptController {

    @Resource
    private IOptService optServiceImpl;

    /**
     * 操作日志分页查询
     * @param pageRequest
     * @param optLogBean
     * @return
     */
    @GetMapping(value ="/page",produces = {"application/json;charset=utf-8"})
    public TableResult<OptLogBean> findAllOptLog(PageRequest pageRequest, OptLogBean optLogBean){
        System.out.println(pageRequest);
        System.out.println(optLogBean);
        PageInfo<OptLogBean> pageInfo=optServiceImpl.findAllOptLog(pageRequest,optLogBean);
        System.out.println(pageInfo);
        return  new TableResult<>(pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * 修改部门信息
     * @param optLogBean
     * @return
     */
    @PutMapping(value = "/update",produces = {"application/json;charset=utf-8"})
    public ResultMsg update(@RequestBody OptLogBean optLogBean){
        System.out.println("-------------修改日志信息");
        System.out.println(optLogBean+"-------------修改日志信息");
        ResultMsg res = new ResultMsg(200,"操作成功",null);
        int row=optServiceImpl.updateOptLog(optLogBean);
        if(row == 1){
            return res;
        }else{
            res.setCode(10000);
            res.setMsg("修改失败");
            return res;
        }
    }

    /**
     * 删除日志
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}",produces = {"application/json;charset=utf-8"})
    public ResultMsg deleteDept(@PathVariable("id") Long id){
        System.out.println("这是删除日志controller"+id);
        ResultMsg res = new ResultMsg(200,"操作成功",null);
        if(id != null) {
            optServiceImpl.deleteOpt(id.intValue());
            return res;
        }else{
            res.setCode(10000);
            res.setMsg("更改失败");
            return res;
        }
    }
}
